package com.googlecode.gaal.vis.impl;

import com.googlecode.gaal.vis.api.EdgeStyle;
import com.googlecode.gaal.vis.api.NodeStyle;

public class TikzConstants {

    private static final String[] COLORS = { "blue", "orange", "magenta", "cyan", "purple", "yellow", "olive",
            "orange", "magenta", "cyan", "purple", "yellow", "olive" };
    private static final String BLUE = "blue!";
    private static final String RED = "red!";
    private static final String GREEN = "green!";
    private static final String ORANGE = "orange!";
    public static final NodeStyle LIGHT_BLUE_CELL = new TikzNodeStyle("lbluecell", BLUE + 10, BLUE + 10);
    public static final NodeStyle BLUE_CELL = new TikzNodeStyle("bluecell", BLUE + 50, BLUE + 50, false);
    public static final NodeStyle RED_CELL = new TikzNodeStyle("redcell", RED + 50, RED + 50, false);
    public static final NodeStyle GREEN_CELL = new TikzNodeStyle("greencell", GREEN + 50, GREEN + 50, false);
    public static final NodeStyle ORANGE_CELL = new TikzNodeStyle("dorangecell", ORANGE + 100, ORANGE + 100, false);
    public static final EdgeStyle DASHED_EDGE = new TikzEdgeStyle("dashededge", "red", "dashed", "->");
    public static final EdgeStyle RED_DOTTED_EDGE = new TikzEdgeStyle("reddashededge", "red", "densely dotted", "->");
    public static final EdgeStyle GREEN_DOTTED_EDGE = new TikzEdgeStyle("greendashededge", "green", "densely dotted",
            "->");
    public static final EdgeStyle BLACK_VECTOR = new TikzEdgeStyle("blackedge", "black", "thick", "->");
    public static final NodeStyle[] NODE_STYLES = new NodeStyle[COLORS.length];
    public static final NodeStyle[] CELL_STYLES = new NodeStyle[COLORS.length];
    public static final EdgeStyle[] EDGE_STYLES = new EdgeStyle[COLORS.length];
    public static final EdgeStyle[] VECTOR_STYLES = new EdgeStyle[COLORS.length];

    static {
        for (int i = 0; i < COLORS.length; i++) {
            NODE_STYLES[i] = new TikzNodeStyle(COLORS[i] + "node", COLORS[i] + "!" + 30, COLORS[i] + "!" + 50);
            CELL_STYLES[i] = new TikzNodeStyle(COLORS[i] + "cell", COLORS[i] + "!" + 30, COLORS[i] + "!" + 30);
            EDGE_STYLES[i] = new TikzEdgeStyle(COLORS[i] + "edge", COLORS[i], "thick", "-o");
            VECTOR_STYLES[i] = new TikzEdgeStyle(COLORS[i] + "vec", COLORS[i], "thick", "-stealth");
        }

    }
}

class TikzNodeStyle implements NodeStyle {
    private final String name;
    private final String fillColour;
    private final String drawColour;
    private final boolean isBold;

    public TikzNodeStyle(String name, String fillColour, String drawColour) {
        this(name, fillColour, drawColour, true);
    }

    public TikzNodeStyle(String name, String fillColour, String drawColour, boolean isBold) {
        this.name = name;
        this.fillColour = fillColour;
        this.drawColour = drawColour;
        this.isBold = isBold;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getFillColour() {
        return fillColour;
    }

    @Override
    public String getDrawColour() {
        return drawColour;
    }

    @Override
    public String toString() {
        return String.format("draw=%s,fill=%s", drawColour, fillColour);
    }

    @Override
    public boolean isBold() {
        return isBold;
    }
}

class TikzEdgeStyle implements EdgeStyle {

    private final String name;
    private final String colour;
    private final String line;
    private final String arrow;

    public TikzEdgeStyle(String name, String colour, String line, String arrow) {
        this.name = name;
        this.colour = colour;
        this.line = line;
        this.arrow = arrow;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getColour() {
        return colour;
    }

    @Override
    public String getArrow() {
        return arrow;
    }

    @Override
    public String toString() {
        return String.format("%s,%s,%s", line, colour, arrow);
    }

}
